// pages/orderssecurity/orderssecurity.js
const util = require("../../utils/util.js");
var app = getApp();
const requestManager = require("../../utils/request.js");
var router = require('../../utils/router.js');
const pageName = "PersonalCenter "
Page({
  /**
   * 页面的初始数据
   */
  data: {
    serviceType:[], // 选择服务类型
    detailData: null,
    deliveryVisible: false,
    logisticsVisible: false,
    serviceVisible: false
  },
  //获取订单详情数据
  getDetaildata(orderid) {
    let params = {
      userId: util.getUserInfo().userId,
      id: orderid
    }
    requestManager.getDataResult(requestManager.order_view, params, "GET").then(res => {
      this.setData({
        detailData: res.data
      })
    })
  },
  handleDailogdelivery(event) {
    let vm = this
    if(event.currentTarget.id=="ok"){
      console.log(event.currentTarget)      
      requestManager.getDataResult(requestManager.confirm_receipt, {
        userId:util.getUserInfo().userId,
        orderId:this.data.detailData.id,
        tradeNo:this.data.detailData.tradeNo
      }, "POST").then(res => {
        // this.setData({
        //   serviceType: res.list ? res.list : [],
        // })
        this.getDetaildata(vm.data.detailData.id)
      })
    }
    this.setData({
      deliveryVisible: !this.data.deliveryVisible
    })
  },
  handlelogisticsVisible() {
    this.setData({
      logisticsVisible: !this.data.logisticsVisible
    })
  },
  handleserviceVisible() {
    this.setData({
      serviceVisible: !this.data.serviceVisible
    })
  },
  // 退款
  handleRefund(event) {
    this.handleserviceVisible()
  },
  handleCheckServer(event){
    this.handleserviceVisible()
    let url = "/pages/reimburse/reimburse";
    router.route.setAction(router.NAVIGATE_TO)
      .setParams([`id=${event.currentTarget.id}&orderId=${this.data.detailData.id}`])
      .setUrl(url)
      .run()
  },
  // 获取售后服务类型
  getServiceType(){
    requestManager.getDataResult(requestManager.service_type, {}, "GET").then(res => {
      this.setData({
        serviceType: res.list ? res.list : [],
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getServiceType()
    this.getDetaildata(options.orderid)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})